package com.hyh.admin.controller.resources;

import com.hyh.ad.common.annotation.Log;
import com.hyh.ad.common.core.controller.BaseController;
import com.hyh.ad.common.core.domain.AjaxResult;
import com.hyh.ad.common.core.page.TableDataInfo;
import com.hyh.ad.common.enums.BusinessType;
import com.hyh.ad.common.utils.SecurityUtils;
import com.hyh.admin.domain.resources.ResourcesComment;
import com.hyh.admin.mapper.resources.ResourcesCommentMapper;
import com.hyh.admin.mapper.resources.ResourcesMapper;
import com.hyh.admin.service.IResourcesCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/resources/comment")
@Api(tags = "资源评论管理")
public class ResourcesCommentController extends BaseController {
    @Autowired
    private IResourcesCommentService resourcesCommentService;

    /*
     *  资源评论列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "资源评论列表")
    public AjaxResult list(ResourcesComment resourcesComment) {
        return AjaxResult.success(resourcesCommentService.selectResourcesComment(resourcesComment));
    }

    /*
     *  更新资源评论
     */
    @PutMapping("/update")
    @ApiOperation(value = "更新资源评论")
    public AjaxResult update(ResourcesComment resourcesComment) {
        return AjaxResult.success(resourcesCommentService.updateResourcesComment(resourcesComment));
    }

    /*
     *  删除资源评论
     */
    @DeleteMapping("/delete")
    @ApiOperation(value = "删除资源评论")
    public AjaxResult delete(ResourcesComment resourcesComment) {
        return AjaxResult.success(resourcesCommentService.deleteResourcesComment(resourcesComment));
    }

    /*
     *  新增资源评论
     */
    @PostMapping("/insert")
    @ApiOperation(value = "新增资源评论")
    public AjaxResult insert(@RequestBody ResourcesComment resourcesComment) {
        return AjaxResult.success(resourcesCommentService.insertResourcesComment(resourcesComment));
    }

    /*
     *  根据用户id查询资源评论
     */
    @GetMapping("/listByUserId")
    @ApiOperation(value = "根据用户id查询资源评论")
    public AjaxResult listByUserId() {
        return AjaxResult.success(resourcesCommentService.selectResourcesCommentByUserId(SecurityUtils.getLoginUser().getUser().getId()));
    }

    /*
     *  根据父评论id查询资源评论
     */
    @GetMapping("/listByParentId/{parentId}")
    @ApiOperation(value = "根据父评论id查询资源评论")
    public AjaxResult listByParentId(@PathVariable String parentId) {
        return AjaxResult.success(resourcesCommentService.selectResourcesCommentByParentId(parentId));
    }

    /*
     *  批量删除资源评论
     */
    @DeleteMapping("/deleteBatch/{ids}")
    @ApiOperation(value = "批量删除资源评论")
    @PreAuthorize("hasAnyAuthority('sys:admin:permission','sys:crud:comment')")
    @Log(businessName = BusinessType.DELETE, operationModule = "批量删除资源评论")
    public AjaxResult deleteBatch(@PathVariable String[] ids) {
        return AjaxResult.success(resourcesCommentService.deleteResourcesCommentBatch(ids));
    }


    /*
     * 查询所有评论列表
     */
    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有评论列表")
    @PreAuthorize("hasAnyAuthority('sys:admin:permission','sys:crud:comment')")
    public TableDataInfo listAll(ResourcesComment resourcesComment) {
        startPage();
        return getDataTable(resourcesCommentService.selectResourcesCommentAll(resourcesComment));
    }
}
